package heima.redPacket;

import java.util.List;
import java.util.Random;
import java.util.concurrent.Callable;

public class GetRedPacket implements Callable<Integer> {
    private List<Integer> redPackets;

    public GetRedPacket(List<Integer> redPackets){
        this.redPackets = redPackets;
    }

    @Override
    public Integer call() throws Exception {
        Random random = new Random();
        synchronized (this){
            int index = random.nextInt(0, this.redPackets.size());
            return this.redPackets.remove(index);
        }
    }
}
